﻿Shader "Kun URP/Post Process/KawaseBlur"
{
    Properties
    {
        [HideInInspector]_MainTex("MainTex", 2D)= "white" {}
    }
    SubShader
    {
        Tags{
            "RenderPipeline"="UniversalRenderPipeline"
        }
        Cull Off ZWrite Off ZTest Always
        HLSLINCLUDE
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        CBUFFER_START(UnityPerMaterial)
            float _BlurRadius;
            float4 _MainTex_TexelSize;
        CBUFFER_END
        TEXTURE2D( _MainTex);
        SAMPLER(sampler_MainTex);
        struct Attributes
        {
            float4 positionOS           : POSITION;
            float2 uv                   : TEXCOORD;
        };
        struct Varyings
        {
            float4 positionCS           : SV_POSITION;
            float2 uv                   : TEXCOORD;
        };
        ENDHLSL
        pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            Varyings vert(Attributes input)
            {
                Varyings output;
                output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
                output.uv = input.uv;
                return output;
            }
            half4 frag(Varyings input) : SV_TARGET
            {
                half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
                tex += SAMPLE_TEXTURE2D(
                    _MainTex,
                    sampler_MainTex,
                    input.uv + float2(-1, -1) * _MainTex_TexelSize.xy * _BlurRadius
                );
                tex += SAMPLE_TEXTURE2D(
                    _MainTex,
                    sampler_MainTex,
                    input.uv + float2(-1, 1) * _MainTex_TexelSize.xy * _BlurRadius
                );
                tex += SAMPLE_TEXTURE2D(
                    _MainTex,
                    sampler_MainTex,
                    input.uv + float2(1, -1) * _MainTex_TexelSize.xy * _BlurRadius
                );
                tex += SAMPLE_TEXTURE2D(
                    _MainTex,
                    sampler_MainTex,
                    input.uv + float2(1, 1) * _MainTex_TexelSize.xy * _BlurRadius
                );
                return tex / 5.0;
            }
            ENDHLSL
        }
    }
}
